package com.rfs.juc;
import java.util.concurrent.TimeUnit;

/**
 * 死锁演示
 *
 * @author renfushuai
 * @date 2022/12/05
 */
public class DeadLockDemo {
    private static String A="A";
    private static String B="B";

    public static void main(String[] args) {
        new DeadLockDemo().deadLock();
    }
    private void deadLock() {
        new Thread(()->{
            synchronized (A){
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (B) {
                    System.out.println("1");
                }
            }
        }).start();
        new Thread(()->{
            synchronized (B){
                synchronized (A){
                    System.out.println("2");
                }
            }
        }).start();
    }
}
